const { NestFactory } = require('@nestjs/core');
const { CasinoModule } = require('./nestjs-app/src/modules/casino/casino.module');
const { CasinoSchedulerService } = require('./nestjs-app/src/modules/casino/services/casino-scheduler.service');

async function testCasinoSchedulerTransaction () {
  console.log('🔄 开始测试娱乐城调度器事务处理...');

  try {
    // 创建NestJS应用
    const app = await NestFactory.createApplicationContext(CasinoModule);

    // 获取调度器服务
    const schedulerService = app.get(CasinoSchedulerService);

    console.log('✅ 成功获取娱乐城调度器服务');

    // 测试手动触发期数轮转
    console.log('🔄 测试手动触发期数轮转...');
    const rotationResult = await schedulerService.manuallyTriggerRoundRotation();
    console.log('期数轮转结果:', rotationResult);

    // 测试手动创建新期数
    console.log('🔄 测试手动创建新期数...');
    const createResult = await schedulerService.manuallyCreateRounds();
    console.log('创建期数结果:', createResult);

    // 测试手动关闭期数
    console.log('🔄 测试手动关闭期数...');
    const closeResult = await schedulerService.manuallyCloseRounds();
    console.log('关闭期数结果:', closeResult);

    // 测试手动结算
    console.log('🔄 测试手动结算...');
    const settlementResult = await schedulerService.manuallyTriggerSettlement();
    console.log('结算结果:', settlementResult);

    console.log('✅ 娱乐城调度器事务处理测试完成');

    // 关闭应用
    await app.close();
  } catch (error) {
    console.error('❌ 测试失败:', error.message);
    console.error('错误详情:', error);
  }
}

// 运行测试
testCasinoSchedulerTransaction();
